package com.qfedu.utils;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * 千锋Java,为你而生！
 *
 * @Author: Feri
 * @Date:2024/11/19 14:50
 * @Modified:
 */
public class DateUtil {

    /**
     * 当前日期和传递的日期相差的天数*/
    public static Integer diffDay(Date date){
        return diffDay(date,new Date());
    }
    /**
     * 2个日期相差的天数
     * date2-date1*/
    public static Integer diffDay(Date date1,Date date2){
        LocalDate start = LocalDate.of(date1.getYear(), date1.getMonth(), date1.getDate());
        LocalDate end = LocalDate.of(date2.getYear(), date2.getMonth(), date2.getDate());

        long daysBetween = ChronoUnit.DAYS.between(start, end);
        return (int)daysBetween;
    }
}
